<?php
/**
 * This class represents an article field
 *
 * @license    GPL
 * @version    Release: @package_version@
 * @since      Class available since Release 0.1
 * @package    DigitalPublisher
 */
abstract class DigitalPublisher_Article_Field_Abstract 
{
	/*
	 * Primary key fields
	 */
	protected $_articleId;
	protected $_moduleFieldName;
	protected $_moduleFieldModuleIdentifier;
	
	/*
	 * Other fields
	 */
	/**
	 * @var mediumblob
	 */
	protected $_value;
	/**
	 * @var string
	 */
	protected $_displayName;
	
	/**
	 * @var string Maximum lenght: 45 chars
	 */
	protected $_type;
	
	protected $_formElementClass;
	protected $_formElement;
    
	public function __construct ( $articleId, $moduleFieldName, $moduleFieldModuleIdentifier ) 
	{
    	if (null === $articleId || null === $moduleFieldName || null === $moduleFieldModuleIdentifier) {
    		throw new Exception(sprintf('All parameters ($articleId, $moduleFieldName, $moduleFieldModuleIdentifier) are mandatory for instantiation of %s.', __CLASS__));
    	}
    	
    	$this->_articleId = $articleId;
    	$this->_moduleFieldName = $moduleFieldName;
    	$this->_moduleFieldModuleIdentifier = $moduleFieldModuleIdentifier;
    }
    
    /**
     * Get the value of this field
     * @return string The value of this field
     */
    public function getValue () 
    {
    	return $this->_value;
    }
    
    /**
     * Set the value of this field
     * @param mixed $value The value you want to set. Can be any type of content.
     */
    public function setValue ( $value ) 
    {
    	$this->_value = $value;
    	
    	// Set the value of the form element as well.
    	// Not using getFormElement here, as we want to prevent instantiating
    	if (null !== $this->_formElement) {
			$this->_formElement->setValue( $value );
    	}
    	return $this;
    }
    
    public function getFormElement() 
    {
    	if (null === $this->_formElement) {
			$this->_formElement = new $this->_formElementClass( $this->_moduleFieldName );
    	}
    	return $this->_formElement;
    }
    
//    public abstract function isValid();
//    public abstract function filter ( $value );
}
